#ifndef UNREALHANDLER_H
#define UNREALHANDLER_H

#include "main.h"
#include <string.h>
#include "gamehandler.h"
#include "logviewer.h"
#include "unrealmap.h"
#include "unrealstream.h"
#include "routemapdraw.h"
#include "unrealmapdraw.h"
#include "unrealcontrollerbot.h"


using namespace Glib;
using namespace Gtk;
using namespace Gio;

class UnrealHandler;
class UnrealControllerBot;

struct globalGameInfo{
    ustring Gametype;
    bool WeaponStay;
    bool GamePaused;
    bool BotsPaused;
    ustring Level;//map
    int GoalTeamScore;
    int TimeLimit;
    int MaxTeams;
    int MaxTeamSize;
    UnrealPlace* RedBaseLocation;
    UnrealPlace* BlueBaseLocation;

};


class UnrealHandler : public GameHandler<UnrealBot>
{
    public:
        /** Default constructor */
        globalGameInfo gameInfos;
        UnrealMap map;
        UnrealMapDraw* mapDraw;
        ustring serverAdress;
        unsigned port, controllerport;
		
        UnrealHandler(ustring adres="localhost", unsigned port=3000, unsigned controllerport = 3001);
        /** Default destructor */
        virtual ~UnrealHandler();

        virtual UnrealControllerBot* createControllerBot();

		virtual void addControllerBot();
        virtual void addBot(UnrealBot& bot){
            if (&bot == 0){
                cout << "no bot created" << endl;
                return;
            }
            cout << "adding";
            cout.flush();
            bot.handler = this;
            return this->GameHandler<UnrealBot>::addBot(bot);
        }
        virtual void stopAll(){

        }
        virtual void resetAll(){

        }
        int botcounter;
		
		virtual void reconnectAll(){
			FORALL(Bot*,b,allbots){
				((UnrealBot*) *b)->connection->close();
				((UnrealBot*) *b)->state=awaiting_connect;
			}
		}
		
        virtual UnrealBot* createBot(){

            UnrealBot* nb = new UnrealBot(refSocketClient, serverAdress, port);
            char buf[10];
            sprintf(buf, "Bot%i", botcounter++);
            nb->name=ustring(buf);
            return nb;
    }
    protected:
    private:

//    Glib::RefPtr<Gio::Socket> refSocket;
    Glib::RefPtr<Gio::SocketClient> refSocketClient;
};

#endif // UNREALHANDLER_H
